package string;

import java.util.Scanner;

public class MatchesDemo {
    public static void main(String[] args) {
        //
        /*
        邮箱的正则表达式：
        [a-zA-Z0-9_]+@[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+
        * */

        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入邮箱：");
        //
        String regex="[a-zA-Z0-9_]+@[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+";
        String email=scanner.nextLine();
        boolean match=email.matches(regex);
        if (match){
            System.out.println("邮箱格式正确");
        }else {
            System.out.println("邮箱格式错误");
        }

        boolean match1=email.matches("[a-zA-Z0-9_]+@[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+");
        if (match1){
            System.out.println("邮箱格式正确1");
        }else {
            System.out.println("邮箱格式错误1");
        }
    }
}
